<?php

	/* SVN FILE: $Id: transact.visioni.php 61 2011-01-23 22:08:36Z andreoletti $ */
	
	/**
	 * Project Name : arcadia
	 *
	 * @author $Author: andreoletti $
	 * @version $Revision: 61 $
	 * @lastrevision $Date: 2011-01-23 23:08:36 +0100 (dom, 23 gen 2011) $
	 * @filesource $URL: http://svn.fletchlynd.com/arcadia/trunk/visioni/transact.visioni.php $
	 */

	// transact.visioni.php E' UTILIZZATO PER IL BOTTONE 'PROROGA AUTORIZZ.'

	require_once 'include/functions.php';
	require_once 'include/const.inc.php';
	require_once '../include/auth.inc.php';
	require_once '../include/conn.inc.php';

	
	$sScript = fnCurrentScript();
	$sSCRIPT_ROOT_PATH = (fnIsScriptInRoot() ? '.' : '..'); // Variabile utilizzata in template.php
	
	fnGetValueFromPOST();
	
	fnViewConst($sViewItemLink);
	
	$aPostedValues = fnGetValueFromPOST();

	$sBacklink = fnHtmlBacklinkFull('get', 'index.php', $bSEARCH_FORM_SHOW, $bTagsShow);

	if (!isset($iTab) || !isset($aTabsLabels[$iTab])) {
		$iTab =  $iTabDefault;
	}
	
	fnFieldsDataTypeArray($aForms[$iTab]['sFormTable']);

	if (isset($iView) && !empty($iView))
		$iAccessLvl = fnViewAccessLvl($iView, $aTABLE, $aTABLE_SECURITY_CHECK);
	else
		$iAccessLvl = fnGetAccessLvl();
		
	if (is_allowed('edit', $iAccessLvl)) {

		switch ($sAction) {

			case "extend":
			
				$bError = fnCheckView ($iView, $sViewSelectFrom, $sViewSelectGroupBy, 'bError');
				
				if ($bError == false) {
					// RINNOVO AUTORIZZAZIONE
					$sQuery = "INSERT INTO `".$aForms[$iTab]['sFormTable']."` (sDescrizione, sUnita, sUnitaEmail, sFornitore, dtInizio, sNote, dtIngresso, sBollaIn)
								SELECT sDescrizione, sUnita, sUnitaEmail, sFornitore, dtInizio, sNote, dtIngresso, sBollaIn
								FROM `".$aForms[$iTab]['sFormTable']."` WHERE id = '$iView'";
					$rResult = custom_mysql_query($sQuery);	
					$iNew = mysql_insert_id($rConn);
					$sRedirect = "$sViewItemLink?iView=".$iNew."&sAction=edit&sMsg=new-extend";
					fnUpdateLog('NEW RECORD', $iNew, $sViewSelectFrom, 'I');				
					$sQuery = "UPDATE `".$aForms[$iTab]['sFormTable']."` SET iRinnovo='1', iViewRinnovo='$iNew', tsLastModify=CURRENT_TIMESTAMP()  WHERE id = '$iView'";
					$rResult = custom_mysql_query($sQuery);	
					fnUpdateLog('RECORD EDITED', $iView, $sViewSelectFrom);
				} else {
					$sRedirect = "./$sViewItemLink?iView=$iView&iTab=$iTab&sMsg=record-not-found";
					fnUpdateLog('RECORD NOT FOUND', $iView, $sViewSelectFrom, 'E');
				
				} 	
				
				break;
			
			default:
				$sRedirect = "./$sViewItemLink?iView=$iView&iTab=$iTab&sMsg=low-rights";
				fnUpdateLog('ACTION NOT VALID', $iView, $sViewSelectFrom, 'E');
				break;
				
		}
 
	} else {
		$sRedirect = $sBacklink.($sBacklink == 'index.php' ? '?' : '&').'sMsg=low-rights';
		fnUpdateLog('LOW RIGHTS', $iView, $sViewSelectFrom, 'S');
	
	}

	fnHtmlTransactFooter($sQuery, $sRedirect);

?><?php if (!fnShowDebugMsg())  { ?>	<html><body bgcolor="#fff"></body></html> <?php } ?>